<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串方法</title>
</head>
<body>
<!--replace() 方法用另一个值替换在字符串中指定的值 只替换首个匹配-->
<button onclick="myFunction()">替换</button>
<p id="demo">请访问 Microsoft 和 Microsoft！</p>
<script>
  function myFunction() {
    var str = document.getElementById("demo").innerHTML;
    var txt = str.replace("Microsoft","W3School");
    document.getElementById("demo").innerHTML = txt;
  }
</script>

</body>
</html>